<?php
session_start();
define('web_s', 'johnsongod');
require(dirname(__FILE__) . '/includes/init.php');
$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
$smarty->assign('act', $act);

if(!$act){
	$smarty->assign('title', '登陆');
}elseif($act == 'submit'){
	$admin_username = isset($_POST['admin_username']) ? $_POST['admin_username'] : '';
	if(!$admin_username){
		exit('admin_username为空');
	}
	$admin_password = isset($_POST['admin_password']) ? $_POST['admin_password'] : '';
	$r = $db->getOne("select count(*) from m_admin where admin_username = '{$admin_username}'");
	if($r <= 0){
		exit('用户名不存在');
	}
	$r = $db->getRow("select * from m_admin where admin_username = '{$admin_username}'");
	if(md5(md5($admin_password).$r['admin_pwd_other']) != $r['admin_password']){
		exit('密码错误');
	}
	$_SESSION['admin_id'] = $r['admin_id'];
	$_SESSION['admin_permissions'] = $r['admin_permissions'] == 'all' ? $r['admin_permissions'] : explode(',', $r['admin_permissions']);
	header('Location: index.php');
}


$smarty->display('login.htm');